package com.harmay.center.monitor.threadpool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author Zuper
 * @version 1.0
 * @date 2022/3/30 14:23
 * 创建线程池
 */
public class TreadPoolExecutorSinglton {

    private static int coreSize = 1;
    private static int maxSize = 5;
    private static long keepalived = 0L;
    private static TimeUnit unit = TimeUnit.SECONDS;
    private static BlockingQueueWrapper queue = new BlockingQueueWrapper(200);

    private TreadPoolExecutorSinglton() {
    }

    public static volatile ExecutorService pool = new ThreadPoolExecutor(coreSize, maxSize, keepalived, unit, queue);

    public static ExecutorService initTreadPool() {

        if (pool == null) {
            synchronized (TreadPoolExecutorSinglton.class) {
                if (pool == null) {
                    pool = new ThreadPoolExecutor(coreSize, maxSize, keepalived, unit, queue);
                }
            }
        }
        return pool;
    }

}
